<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

class m_backoffice_services_ModulesService extends f_core_Service
{
	/**
	 * @var m_backoffice_services_ModulesService
	 */
	private static $instance;
	
	/**
	 * Constructor
	 */
	private function __construct()
	{
		// Code if needed...
	}
	
	/**
	 * @return m_backoffice_services_ModulesService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = new self();
		}
		return self::$instance;
	}

    public function getModulesList()
    {
        $packageFiles = f_file_Resolver::getInstance()->fromDirectory(MODULES_DIR)->setRecursive(true)->setMask('package.xml')->find();

		$modules = array();

		foreach($packageFiles as $file)
		{
            $desc = f_package_Description::getInstance($file);

            if(!is_null($desc))
            {                
                if($desc->getType() == 'extension' && $desc->hasModuleRootNode())
                {
                    $modules[] = $desc;
                }
            }
		}

        return $modules;
    }
}